package com.szgr.baoyin.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.szgr.baoyin.R;
import com.szgr.baoyin.model.CardType;
import com.szgr.baoyin.model.DYCard;
import com.szgr.baoyin.utils.ViewFindUtils;

import java.util.List;

/**
 * Created by yang on 15/12/14.
 */
public class DYCardListAdapter extends BaseAdapter {
    private Context mContext;
    private List<DYCard> data;
    public DYCardListAdapter(Context context, List<DYCard> data){
        mContext = context;
        this.data = data;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_dycard_list_view,parent,false);
        }

        ImageView img_head = ViewFindUtils.hold(convertView,R.id.card_view);
        TextView tv_name = ViewFindUtils.hold(convertView,R.id.card_name);
        TextView tv_num = ViewFindUtils.hold(convertView,R.id.card_number);

        DYCard dyCard = data.get(position);
        CardType card = dyCard.getCard();
        switch (card.getCard_id()){
            case "1":
                img_head.setImageResource(R.drawable.card_07);
                break;
            case "2":
            case "3":
            case "4":
                img_head.setImageResource(R.drawable.card_06);
                break;
            case "5":
                img_head.setImageResource(R.drawable.card_05);
                break;
            case "6":
                img_head.setImageResource(R.drawable.card_04);
                break;
            case "7":
                img_head.setImageResource(R.drawable.card_03);
                break;
            case "8":
                img_head.setImageResource(R.drawable.card_02);
                break;
            case "9":
                img_head.setImageResource(R.drawable.card_01);
                break;

        }

        tv_name.setText(card.getCard_name());
        tv_num.setText(dyCard.getCard_sn());

        return convertView;
    }

    public void setData(List<DYCard> data) {
        this.data = data;
        notifyDataSetChanged();
    }
}
